package SpringBoot.spring_boot_starter_freemarker.D01_HelloWorld;

import org.springframework.boot.Banner;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration;
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import com.titan.core.web.utils.SpringBootUtils;

/**

 */

@Configuration
@Import({
    // Tomcat，可以使用@RestController, 
    DispatcherServletAutoConfiguration.class,
    EmbeddedServletContainerAutoConfiguration.class,      // 注册容器类型
    ServerPropertiesAutoConfiguration.class,              // 用于初始化容器相关的配置属性，如服务地址、端口、contextPath，并根据当前容器类型初始化各个容器的特有属性，如tomcat的maxThreads、uriEncoding等等，其对应的属性类为ServerProperties；
    HttpEncodingAutoConfiguration.class,                  // 注册http编码过滤器
    ErrorMvcAutoConfiguration.class,                    // 注册异常处理器，如果不添加，会存在后台传递异常和登录超时等问题
    // SpringMvc，可以访问静态资源
    WebMvcAutoConfiguration.class,                        // 注册SpringMvc相关处理器，如ResourceResolver、RequestMappingHandlerAdapter、ExceptionHandlerExceptionResolver、ViewResolver、LocaleResolver，等等
    HttpMessageConvertersAutoConfiguration.class,         // 注册json或者xml处理器
    // Core AOP
    AopAutoConfiguration.class,
    // XML JSON
    JacksonAutoConfiguration.class,
    // Template Engines
    FreeMarkerAutoConfiguration.class,
})
@ComponentScan(value = { "SpringBoot.spring_boot_starter_freemarker.D01_HelloWorld.config"
                       , "SpringBoot.spring_boot_starter_freemarker.D01_HelloWorld.controller"
                       })
public class Application {
	public static void main(String[] args) {
		new SpringApplicationBuilder()
			.bannerMode(Banner.Mode.OFF)
	        .sources(Application.class)
            .listeners(SpringBootUtils.registerApplicationListener())
	        .web(true)
	        .run(new String[]{
	                "--debug=false"
                  , "--server.port=9999"
                  , "--spring.freemarker.enabled=true"
                  , "--spring.freemarker.cache=false"
                  , "--spring.freemarker.charset=UTF-8"
                  , "--spring.freemarker.content-type=text/html"
                  , "--spring.freemarker.template-loader-path=classpath:/SpringBoot/spring_boot_starter_freemarker/D01_HelloWorld/web/"
                  , "--spring.freemarker.check-template-location=true"
                  , "--spring.freemarker.allow-request-override=true"
                  , "--spring.freemarker.expose-request-attributes=true"
                  , "--spring.freemarker.request-context-attribute=request"
//                  , "--spring.freemarker.prefix=classpath:/SpringBoot/spring_boot_starter_freemarker/D01_HelloWorld/web/"
                  , "--spring.freemarker.suffix=.ftl"
//                  , "--="
                  
//                  spring.freemarker.allow-session-override=false # Whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name.
//                  spring.freemarker.expose-session-attributes=false # Whether all HttpSession attributes should be added to the model prior to merging with the template.
//                  spring.freemarker.expose-spring-macro-helpers=true # Whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext".
//                  spring.freemarker.prefer-file-system-access=true # Whether to prefer file system access for template loading. File system access enables hot detection of template changes.
//                  spring.freemarker.request-context-attribute= # Name of the RequestContext attribute for all views.
//                  spring.freemarker.settings.*= # Well-known FreeMarker keys which are passed to FreeMarker's Configuration.
//                  spring.freemarker.view-names= # White list of view names that can be resolved.
	        });
	}
}
